|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectalgalcommand.io.xml.Element
public class Element
The SAX XML parser packaged with Java is not thread safe and fails miserably in the true multithreaded application such as this. As such, this class is part of a bare-bones XML writing and reading parser that is fully thread safe.
This class IS thread-safe! Copyright Owner: Michigan State University, license number TEC2011-002101Prov
| Constructor Summary | |
|---|---|
Element()
default contsructor, try not to use it if you don't have to |
|
Element(java.lang.String tagname)
Constructs an Element object with the specified tagname |
|
| Method Summary | |
|---|---|
void |
addAttribute(java.lang.String name,
java.lang.String value)
Deprecated. Use setAttribute(name, value) instead; |
void |
addChild(Element child)
Adds an element child inside this tag. Ex:
<font size="2">Greetings <b>friend!</b></font>
In the above code, the children of the font element are (in
order) "Greetings " and b. |
void |
addChild(java.lang.String textChild)
Adds a portion of text as a child to this element. Ex:
<font size="2">Greetings <b>friend!</b></font>
In the above code, the children of the font element are (in
order) "Greetings " and b. |
Element |
clone()
|
boolean |
containsChild(java.lang.Object obj)
Checks to see if the specified object is a child of this element |
int |
countChildren()
Ex:
<font size="2">Greetings <b>friend!</b></font>
In the above code, the font element has 2 children:
"Greetings " and b. |
java.util.List<java.lang.String> |
getAllAttributeNames()
Returns a list of the names of all of the attributes. |
java.lang.String |
getAttributeValue(java.lang.String name)
Retrieves the value of an attribute |
java.lang.Object |
getChild(int index)
Fetches a child from this element. |
java.util.List<Element> |
getChildElementsByName(java.lang.String tagname,
boolean caseSensitive)
Scans through the children of this element and returns those of the type specified. |
java.lang.String |
getTagName()
|
boolean |
hasAttribute(java.lang.String name)
Checks for th eexistance of an attribute |
boolean |
isEmpty()
Determines if this element is empty. |
static void |
main(java.lang.String[] args)
Deprecated. |
void |
removeAllAttributes()
Removes all of the attributes from this element |
void |
removeAllChildren()
Removes all of ht echildren from this element |
void |
removeAttribute(java.lang.String name)
Removes the specified attribute from this element. |
void |
removeChild(int index)
Removes the specified child from this element. |
void |
removeChild(java.lang.Object child)
Removes the specified child from this element. |
void |
setAttribute(java.lang.String name,
java.lang.String Value)
Sets the value of an attribute for this element If the attribute does not already exist, it is automatically created. |
void |
setTagName(java.lang.String tagname)
Sets the name of this tag. |
java.lang.String |
toString()
This will convert this element into its XML representation, returned as a String. |
java.lang.String |
toString(int indentNumber)
Converts this element and all of its children into their XML representation, with the indecated amount of extra indentation. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Element()
public Element(java.lang.String tagname)
tagname - The name of the tag (e.g. <font face="serif"> has a
tagname of "font").
java.lang.IllegalArgumentException - Thrown is tagname is not
a valid name for an XML tag (has innappropriate characters or whitespace).| Method Detail |
|---|
public void addAttribute(java.lang.String name,
java.lang.String value)
setAttribute(name, value) instead;
name - Name of the attributevalue - Value of the attributepublic java.lang.String getAttributeValue(java.lang.String name)
name - The name of the attribute
null if the named
attribute does not exist for this element.
public void setAttribute(java.lang.String name,
java.lang.String Value)
name - The name of the attributeValue - The (new) value of the attribute
java.lang.IllegalArgumentException - Thrown if name is not
a valid name for an XML attribute (has innappropriate characters or whitespace).public boolean hasAttribute(java.lang.String name)
name - Name of the attribute
true if that attribute has been set for this element,
false otherwise.public void removeAttribute(java.lang.String name)
name - The name of the attribute to removepublic void removeAllAttributes()
public java.util.List<java.lang.String> getAllAttributeNames()
public void addChild(java.lang.String textChild)
<font size="2">Greetings <b>friend!</b></font>
font element are (in
order) "Greetings " and b. "Greetings " is a text child and
b is an element child. b has "friend!" as its
child ("friend!" is not a child of font).
textChild - A string of text to addpublic void addChild(Element child)
<font size="2">Greetings <b>friend!</b></font>
font element are (in
order) "Greetings " and b. "Greetings " is a text child and
b is an element child. b has "friend!" as its
child ("friend!" is not a child of font).
child - An element to add as a child to this elementpublic int countChildren()
<font size="2">Greetings <b>friend!</b></font>
font element has 2 children:
"Greetings " and b. "Greetings " is a
text child and b is an element child.
b has one child: "friend!". "friend!"
is not a child of font.
public java.lang.Object getChild(int index)
index - Index of the child (first child is index 0).
public java.util.List<Element> getChildElementsByName(java.lang.String tagname,
boolean caseSensitive)
tagname - Tag name of the elements you want. This is not case
sensitive.
public void removeChild(int index)
index - public void removeChild(java.lang.Object child)
child - The object to be removedpublic void removeAllChildren()
public boolean containsChild(java.lang.Object obj)
obj - An object that may or may not already be a child of this
element.
true if this element has obj as one
of its children.public boolean isEmpty()
public java.lang.String getTagName()
public void setTagName(java.lang.String tagname)
tagname - The new name for this tag.public java.lang.String toString()
toString in class java.lang.ObjecttoString(0).public java.lang.String toString(int indentNumber)
indentNumber - How many extra tabs to indent
public Element clone()
clone in class java.lang.Objectpublic static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||